package com.web;

import com.baselib.BaseSupport;

import com.gjl.lib.*;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.*;
import com.gjl.search.*;
import com.gjl.search.*;

public class Search extends BaseSupport {

	/**
	 * 
	 */
	
	private static final long serialVersionUID = 5776124909172082614L;
	private Map <String,String> conditions;
	private String result = "";
	private int page=1;
	private Map<String,HashMap<String,String>> list;
	

	public String execute()throws IOException{
		
		
		SearchIndex si = new SearchIndex(Configuration.getIndexLawServer(),Configuration.getIndexLawPort());
		IndexQuery iq = new IndexQuery();
		String query = iq.get(conditions, page);
		System.out.println(query);
		DataResult dataResult = new DataResult();		

		byte [] b_query = iq.pro(query, Configuration.getCharset()); 
		
		try {
			//result = new String(si.search(b_query),Configuration.getCharset());
			IndexResult ir = si.search(b_query,Configuration.getCharset());
			list = dataResult.getByIds(ir.getIds());
			Map<String,String> searchResultInfo = ir.get();
			System.out.println(searchResultInfo);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		return SUCCESS;		
	}
	
	public String getPageList(IndexResult ir){
		return "";
	}
	
	public int getPage(){
		return this.page;
	}
	public void setPage(int p){
		this.page=p;
	}
	
	public void setConditions(Map<String, String> conditions){
		this.conditions = conditions;
	}

	public Map<String, String> getConditions(){
		return this.conditions;
	}

	public Map<String,HashMap<String,String>> getList(){		
		return this.list;
	}
	public String getResult(){
		return this.result;
	}
}
